<?php

namespace App\Notifications;

use App\Channels\SmsChannel;
use App\Channels\WechatChannel;
use App\Order;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;

class OrderConfirmed extends Notification
{
    use Queueable;

    protected $order;
    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }

    /**
     * Get the notification's delivery channels.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function via($notifiable)
    {
        return [WechatChannel::class,SmsChannel::class];
    }

    public function toWechat($notifiable) {
        $order = $this->order;


        return $message = [
            'template_id'=> config('wechat.template_id.order_confirm'),
            'url'=>route('home'),
            'data'=> [
                'first'=>'订单支付通知！',
                'keyword1'=>$order->code,
                'keyword2'=>$order->amount,
                'keyword3'=>Carbon::now()->addMinute(30)->format("Y-m-d H:i"),
                'remark'=>'您的订单已出票，快去支付吧！',
            ],
        ];

    }

    public function toSms($notifiable) {
        $order = $this->order;
        return $message = [
            'phone'=> $notifiable->phone,
            'content'=>"您的订单{$order->code}已出票，快去付款吧！"
        ];
    }
    /**
     * Get the mail representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return \Illuminate\Notifications\Messages\MailMessage
     */
    public function toMail($notifiable)
    {
        return (new MailMessage)
                    ->line('The introduction to the notification.')
                    ->action('Notification Action', url('/'))
                    ->line('Thank you for using our application!');
    }

    /**
     * Get the array representation of the notification.
     *
     * @param  mixed  $notifiable
     * @return array
     */
    public function toArray($notifiable)
    {
        return [
            //
        ];
    }
}
